﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace taxibill
{
    class Program
    {
        static int Main(string[] args)
        {
            int kilometres = 0;
            int demurrageMinute = 0;
            int bill = 0;

            try
            {
                if (args.Length == 2)
                {
                    kilometres = Convert.ToInt32(args[0]);
                    demurrageMinute = Convert.ToInt32(args[1]);

                    Taxi taxi = new Taxi(kilometres, demurrageMinute);
                    bill = taxi.CalculateBill();
                    Console.WriteLine("\nYour bill is {0} grn.", bill);
                    Console.Read();

                }
                else if (args.Length == 0)
                {
                    while (kilometres == 0)
                    {
                        Console.WriteLine("Input your parameters:");
                        Console.WriteLine("Kilometres:");
                        kilometres = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Demurrage:");
                        demurrageMinute = Convert.ToInt32(Console.ReadLine());

                        Taxi taxi = new Taxi(kilometres, demurrageMinute);
                        bill = taxi.CalculateBill();
                        Console.WriteLine("\nYour bill is {0} grn.", bill);
                        Console.Read();
                    }

                }
                else
                {
                    Console.Error.WriteLine("\nNot correct number of parameters.");

                //    return 1;
                }
            }
            catch (OverflowException)
            {
                Console.Error.WriteLine("\nToo big parameters.");

              //  return 2;
            }
            catch (FormatException)
            {
                Console.Error.WriteLine("\nNot correct format of parameters.");

            //    return 3;
            }

            return 0;
        }


        class Taxi
        {
            int kilometres;
            int demurrageMinute;
            public Taxi(int kilometres, int demurrage)
            {
                this.kilometres = kilometres;
                demurrageMinute = demurrage;
            }

            public int CalculateBill()
            {
                const int fiveKm = 5;
                const int priceFiveKm = 20;
                int bill = demurrageMinute + priceFiveKm;
                int remainingDistance = kilometres - fiveKm;
                int remainingDistancePrice = 3;

                for (int i = remainingDistance; i > 0; i--)
                {
                    bill += remainingDistancePrice;
                }

                return bill;
            }
        }

    }
}
